﻿namespace Pps.Gui.Controls
{
    using Pps.Gui.Base;

    public class Led : Control
    {
        private bool state;

        public Led()
            : this(0, 0, 20)
        {
        }

        public Led(int x, int y, int diameter)
            : base(diameter, diameter)
        {
            this.Position = new Point(x, y);

            this.state = false;
        }

        public bool State
        {
            get { return this.state; }
            set
            {
                if (this.state != value)
                {
                    this.state = value;
                    this.Invalidate();
                }
            }
        }

        public override Base.Size Size
        {
            get
            {
                return base.Size;
            }
            set
            {
                base.Size = value;
            }
        }

        public void On()
        {
            this.state = true;

            this.Invalidate();
        }

        public void Off()
        {
            this.state = false;

            this.Invalidate();
        }

        protected override void Paint(Graphics graphics)
        {
            graphics.DrawEllipse(Color.Black, 1, this.X + (this.Width / 2), this.Y + (this.Width / 2), (this.Width / 2), (this.Width / 2), this.state ? Color.Red : Color.Green, this.X, this.Y, this.state ? Color.Red : Color.Green, this.X, this.Y, 255);
        }
    }
}